package sivak.net.proc.dyn.single_lib_1;

/**
 * Created with IntelliJ IDEA.
 * User: root
 * Date: 1/23/13
 * Time: 1:27 PM
 * To change this template use File | Settings | File Templates.
 */
public class SingleLLUtils_2 {
    public static int length(Node tail) {
        if (tail == null)
            return 0;
        return 1 + length(tail.next);
    }

    public static int max(Node tail) {
        if (tail == null)
            throw new IllegalArgumentException();
        if (tail.next == null)
            return tail.value;
        return Math.max(tail.value, max(tail.next));
    }

    public static int sum(Node tail) {
        if (tail == null)
            return 0;
        return tail.value + sum(tail.next);
    }
}
